package com.dx.architectureddd.domain.component.flow;

import com.dx.architectureddd.common.enums.NodeNextType;
import com.dx.architectureddd.domain.FlowNodeContext;
import com.dx.architectureddd.domain.NextNode;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import lombok.extern.slf4j.Slf4j;

import java.util.UUID;

/**
 * 过程——内部计算，判定节点走向
 *
 * @author xin.deng
 * @date 2023/09/24
 */
@Slf4j
@LiteflowComponent("FightCmp")
public class FightCmp extends NodeSwitchComponent {
    @Override
    public String processSwitch() {
        FlowNodeContext contextBean = this.getContextBean(FlowNodeContext.class);
        int curLevel = Integer.parseInt(contextBean.getCurLevel());
        log.info("副本等级为：{}", curLevel);
        int level = Integer.parseInt(contextBean.getLevel());
        NextNode nextNode = new NextNode(NodeNextType.NTH);
        if (curLevel - level >= 5) {
            log.info("副本等级过高，通关失败");
            nextNode.setNodeNextType(NodeNextType.FAIL);
        } else if (curLevel % 2 == 0) {
            nextNode.setNodeNextType(NodeNextType.SUC);
            contextBean.setUuid(UUID.randomUUID().toString().replaceAll("-", ""));
            contextBean.setReward("通过成功，并且获取特殊奖励");
        } else {
            log.info("通关成功");
            nextNode.setNodeNextType(NodeNextType.SUC);
            contextBean.setReward("通关成功");
        }
        contextBean.setNextNode(nextNode);
        return nextNode.getNodeNextType().getValue();
    }
}
